package a1_p04_jw_kw.graph;

import java.io.*;

public class GraphIO {
	BufferedReader br;
	DataInputStream in;
	
	public void initializeInputStream(String fileName) {
		try {
			FileInputStream fsstream = new FileInputStream(fileName);
			this.in = new DataInputStream(fsstream);
			
			this.br = new BufferedReader(new InputStreamReader(this.in));
			
		} catch (FileNotFoundException e) {
			System.out.println("File not found!");
			e.printStackTrace();
		}
		
	}
	
	public String getNextLine() {
		String ret = "";
		
		try {
			ret = this.br.readLine();
		} catch (IOException e) {
			System.out.println("Couldnt read from file");
			e.printStackTrace();
		}
		
		return ret;
	}
	
	public void closeInputStream() {
		try {
			this.in.close();
			
		} catch (IOException e) {
			System.out.println("Couldnt close the inputstream");
			e.printStackTrace();
		}
		
	}
	
	public void saveToFile(String text, String file) {
		try {
			FileWriter fw = new FileWriter(file);
			BufferedWriter out = new BufferedWriter(fw);
			out.write(text);
			out.close();
			
		} catch (IOException e) {
			System.out.println("couldnt write file");
			e.printStackTrace();
			
		}
		
		
	}

}
